package cn.lyjuan.archetypes.bms.web;

import cn.lyjuan.base.util.SpringContextHolder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

@SpringBootApplication(scanBasePackages = "cn.lyjuan.archetypes.bms.web")
@MapperScan(basePackages = {
        "cn.lyjuan.archetypes.bms.common.mapper",
        "cn.lyjuan.archetypes.bms.web.mapper"})
public class Application extends SpringBootServletInitializer
{
    private static Logger log = LogManager.getLogger(Application.class);

    /**
     * Tomcat 部署
     *
     * @param application
     * @return
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
    {
        return application.sources(Application.class);
    }

    /**
     * Main方法启动
     *
     * @param args
     */
    public static void main(String[] args)
    {
        ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
        SpringContextHolder holder = new SpringContextHolder();
        holder.setApplicationContext(context);

        Environment env = context.getEnvironment();
        log.info("\n----------------------------------------------------------\n\t" +
                "Application '" + env.getProperty("spring.application.name") + "' is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + env.getProperty("server.port") + "\n\t" +
                "----------------------------------------------------------");
    }
}
